/*
 * software_i2c_master.h
 *
 *  Created on: Jan 11, 2014
 *      Author: bohni
 */

#ifndef SOFTWARE_I2C_MASTER_H_
#define SOFTWARE_I2C_MASTER_H_

#include <avr/io.h>
#include <stdint.h>
#include <util/delay.h>


///////////////////////////////////////////////////////////

// SINGLE MASTER ONLY

//////////////////////////////////////////////////////////////


#define SOFTWARE_I2C_FREQ	100000

#define TIMING_DELAY_US 	(500000/SOFTWARE_I2C_FREQ)

/////////////////////////////////////////////////////////////
// PORT

#define SCL_DDR 	DDRB
#define SCL			PB1
#define SCL_PORT	PORTB

#define SDA_DDR		DDRB
#define SDA_PIN		PINB
#define SDA			PB2
#define SDA_PORT	PORTB

#define USE_INT_PULLUP

void soft_i2c_master_init( void );


uint8_t soft_i2c_start( uint8_t adr );


uint8_t soft_i2c_repstart( uint8_t adr );


void soft_i2c_stop( void );

uint8_t soft_i2c_send_data( uint8_t data );


uint8_t soft_i2c_recieve_data_nack( void );


uint8_t soft_i2c_recieve_data_ack( void );





#endif /* SOFTWARE_I2C_MASTER_H_ */
